package com.cuitrip.business.bill;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cuitrip.business.bill.model.UserAccount;
import com.cuitrip.business.bill.model.UserAccounts;
import com.cuitrip.service.R;
import com.lab.app.customui.CustomUiConfig;
import com.lab.app.customui.CustomUiFragment;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by sheena on 16/4/30.
 */
public class SubmitFailedFragment extends CustomUiFragment {

    public static final String ACCOUNT_KEY = "account";
    public static final String BALANCE_KEY="balance";
    public static final String ALL_ACCOUNTS_KEY="accounts";
    public static final String MSG="msg";

    private UserAccount account;
    private String balance;
    private UserAccounts userAccounts;

    @Bind(R.id.tv_msg)
    TextView mMsg;
    private String msg;

    public static SubmitFailedFragment newInstance(UserAccount account, UserAccounts userAccounts, String balance,String msg) {
        SubmitFailedFragment submitFailedFragment = new SubmitFailedFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable(ACCOUNT_KEY, account);
        bundle.putSerializable(ALL_ACCOUNTS_KEY,userAccounts);
        bundle.putString(BALANCE_KEY,balance);
        bundle.putString(MSG,msg);
        submitFailedFragment.setArguments(bundle);
        return submitFailedFragment;
    }
    @Override
    public boolean initCloseTopBar() {
        return true;
    }

    @Override
    public CustomUiConfig initCustomUiConfig() {
        return null;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState, R.layout.fragment_submit_fail);
        if (getArguments()!=null){
            account = (UserAccount) getArguments().getSerializable(ACCOUNT_KEY);
            balance = getArguments().getString(BALANCE_KEY);
            userAccounts = (UserAccounts) getArguments().getSerializable(ALL_ACCOUNTS_KEY);
            msg = getArguments().getString(MSG);
        }
        return view;
    }

    @Override
    public void initView() {
        ButterKnife.bind(this,getView());
        mMsg.setText(msg);
    }

    @OnClick(R.id.try_again)
    public void tryAgain(){
        onBackPressed();
    }

    @OnClick(R.id.return_action)
    public void back(){
        getHostActivity().getCustomSelfFragmentManager().popBackStackImmediate(WithdrawPageFragment.class.getName(),FragmentManager.POP_BACK_STACK_INCLUSIVE);

    }
}
